import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.Result;

import java.sql.Connection;
import java.sql.DriverManager;

import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import test.generated.tables.Posts;
//import test.generated.Guestbook;
//import test.generated.tables.Posts;
//import test.generated.tables.records.PostsRecord;

public class Main {
 
    public static void main(String[] args) {
        Connection conn = null;
        String userName = "fengyan";
        String password = "Allyes@911";
        String url = "jdbc:mysql://10.200.28.42:9998/test";
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(url, userName, password);

            DSLContext create = DSL.using(conn, SQLDialect.MYSQL);
            Result<Record> result = create.select().from(Posts.POSTS).fetch();

            for (Record r : result) {
                Long id = r.getValue(Posts.POSTS.ID);
                String title = r.getValue(Posts.POSTS.TITLE);
                String description = r.getValue(Posts.POSTS.BODY);

                System.out.println("ID: " + id + " title: " + title + " desciption: " + description);
            }

            conn.close();
        } catch (Exception e) {
            // You'll probably want to handle the exceptions in a real app
            // Don't ever do this silence catch(Exception e) thing. I've seen this in
            // live code and it is horrendous.
            e.printStackTrace();
        } 
 
    }
}